<?php

namespace common\behavior\CommonMessagePushing;

use Webman\Stomp\Client;

/**
 * 任务变更计划时间行为 消息通知
 */
class TaskUpdatePlanBehavior
{
    /**
     * @param $params
     * @return void
     */
    public function run($params)
    {
        if (($params['type'] ?? '') != 'update_plan') {
            return;
        }

        $receiver = $taskAssignInfo['receiver'] ?? [];
        $receiverCc = $taskAssignInfo['receiver_cc'] ?? [];
        foreach ($params['update_keys'] ?? [] as $updateKey) {
            if (!in_array($updateKey, ['plan_end_time', 'plan_delivery_time'])) {
                continue;
            }
            $data = [
                'source_user_id' => $params['operate'] ?? \request()->getUserId(),
                'time' => $params['operate_at'] ?? time(),
                'source_id' => $params['task_id'],
                'source_module_code' => 'task',
                'category' => 'task_update_' . $updateKey,
                'receiver' => $receiver,
                'receiver_cc' => $receiverCc,
            ];
            try {
                trace("common task update plan time push behavior" . request()->getUnionUserId(), 'DEBUG');
                Client::send('common_message_pushing', build_queue_data_with_xu($data));
            } catch (\Throwable $e) {
                trace(format_exception_info($e), 'ERR');
            }
            return; // 只发一条，需要时再修改
        }
    }
}
